// functionPage/components/review-input/review-input.js
import Http from '../../../utils/http.js';
const http = new Http();
const app = getApp();

Component({
    /**
     * 组件的属性列表
     */
    properties: {},

    /**
     * 组件的初始数据
     */
    data: {
        index: '', //审核后刷新数量
        list: [],
        deleteCnt: '', //删除的数量
        recommendCnt: '', //推优数
        unVerifyCnt: '', //未审核数量
        verifyCnt: '', //已审核数量
        PageNo: 0,
        ContentLength: Number,
        Loading: true,
    },
    lifetimes: {
        attached: function () {
            // 在组件实例进入页面节点树时执行
            this.getVerifyList();
        },
    },
    /**
     * 组件的方法列表
     */
    methods: {
        jumpPageTap(e) {
            let url;
            this.setData({
                index: e.currentTarget.dataset.index,
            });
            if (e.currentTarget.dataset.delflg == '02') {
                url =
                    e.currentTarget.dataset.path +
                    '?review=01&id=' +
                    e.currentTarget.dataset.id;
            } else {
                url =
                    e.currentTarget.dataset.path +
                    '?review=02&id=' +
                    e.currentTarget.dataset.id;
            }
            wx.navigateTo({
                url: `${url}`,
            });
        },
        getVerifyList() {
            let _that = this;
            if (
                _that.data.PageNo != 0 &&
                _that.data.ContentLength == _that.data.list.length
            )
                return;
            _that.setData({
                Loading: true,
                PageNo: _that.data.PageNo + 1,
            });
            let data = {
                authId: app.globalData.authId,
                pageNo: _that.data.PageNo,
                pageSize: 20,
            };
            http.getRequest(`cjMap/getVerifyCheckInList`, data).then((res) => {
                if (res.status == 0) {
                    for (let i = 0; i < res.data.length; i++) {
                        res.data[i].updatetime = app.timeago(
                            res.data[i].updatetime
                        );
                        res.data[i].path =
                            '/functionPage/pages/review/checkIn/checkIn';
                        _that.data.list.push(res.data[i]);
                    }
                    _that.setData({
                        list: _that.data.list,
                        deleteCnt: res.typeCnt.deleteCnt, //删除的数量
                        recommendCnt: res.typeCnt.recommendCnt, //推优数
                        unVerifyCnt: res.typeCnt.unVerifyCnt, //未审核数量
                        verifyCnt: res.typeCnt.verifyCnt, //已审核数量
                        Loading: false,
                        ContentLength: res.pager.totalRows,
                    });
                }
            });
        },
        // 审核后刷新
        refresh() {
            let _that = this;
            let data = {
                authId: app.globalData.authId,
                pageNo: 1,
                pageSize: _that.data.index + 10,
            };
            http.getRequest(`cjMap/getVerifyCheckInList`, data).then((res) => {
                if (res.status == 0) {
                    for (let i = 0; i < res.data.length; i++) {
                        if (
                            res.data[i].id ==
                            _that.data.list[_that.data.index].id
                        ) {
                            _that.data.list[_that.data.index].delflg =
                                res.data[i].delflg;
                            _that.data.list[_that.data.index].verifyname =
                                res.data[i].verifyname;
                            _that.data.list[_that.data.index].verifyflg =
                                res.data[i].verifyflg;
                        }
                    }
                    _that.setData({
                        list: _that.data.list,
                        deleteCnt: res.typeCnt.deleteCnt, //删除的数量
                        recommendCnt: res.typeCnt.recommendCnt, //推优数
                        unVerifyCnt: res.typeCnt.unVerifyCnt, //未审核数量
                        verifyCnt: res.typeCnt.verifyCnt, //已审核数量
                    });
                }
            });
        },
    },
});
